with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
With Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with IO; use IO;
with Logging;
with Controller;
with Smart_Arguments;



procedure Mkv2ps3 is

   Video_File : Smart_Arguments.Argument_Type;
   Audio_File : Smart_Arguments.Argument_Type;
   Output_File : Smart_Arguments.Argument_Type;
   Help : Smart_Arguments.Argument_Type;

   InFile1, InFile2, OutFile : IO.File_Type;

   --InFile1Access : File_Type_Access := InFile1'Access;
   --InFile2Access : File_Type_Access := InFile2'Access;
   --OutFileAccess : File_Type_Access := OutFile'Access;
begin

   -- parse args
   Smart_Arguments.Create_Argument
     (Argument    => Output_File,
      Short_Form  => "-o",
      Required    => true,
      Description => "Output file",
      Number_Required_Subargs => 1,
      Subarg_Description => "output");

   Smart_Arguments.Create_Argument
     (Argument    => Video_File,
      Short_Form  => "-v",
      Required    => true,
      Description => "Input video file",
      Number_Required_Subargs => 1,
      Subarg_Description => "video");

   Smart_Arguments.Create_Argument
     (Argument    => Audio_File,
      Short_Form  => "-a",
      Required    => true,
      Description => "Input audio file",
      Number_Required_Subargs => 1,
      Subarg_Description => "audio");

   Smart_Arguments.Create_Argument
     (Argument    => Help,
      Short_Form  => "-h",
      Description => "Help");

   -- validate
   if Smart_Arguments.Argument_Present(Argument => Help) then
      Smart_Arguments.Display_Help(Short_Form_Only => false);
      return;
   end if;

   if not Smart_Arguments.Arguments_Valid then
      Set_Exit_Status(2);
      Put_Line(Standard_Error, Smart_Arguments.Get_Command_Line_Error_Description);
      New_Line;
      Smart_Arguments.Display_Help(Short_Form_Only => false);
      return;
   end if;

   -- begin
   Logging.Info("Creating Video");

   -- read args
   InFile1.Name := To_Unbounded_String(Smart_Arguments.Get_Subargument(Video_File, 1));
   InFile2.Name := To_Unbounded_String(Smart_Arguments.Get_Subargument(Audio_File, 1));
   OutFile.Name := To_Unbounded_String(Smart_Arguments.Get_Subargument(Output_File, 1));

   -- open files
   Logging.Info("Opening : " & To_String(InFile1.Name));
   Stream_IO.Open(InFile1.File, Stream_IO.In_File, To_String(InFile1.Name));
   InFile1.File_Access := Stream_IO.Stream(InFile1.File);

   Logging.Info("Opening : " & To_String(InFile2.Name));
   Stream_IO.Open(InFile2.File, Stream_IO.In_File, To_String(InFile2.Name));
   InFile2.File_Access := Stream_IO.Stream(InFile2.File);

   Logging.Info("Creating : " & To_String(OutFile.Name));
   Stream_IO.Create(OutFile.File, Stream_IO.Out_File, To_String(OutFile.Name));
   OutFile.File_Access := Stream_IO.Stream(OutFile.File);

   --Controller.Start(InFile1, OutFile);
   Controller.StartAC3(InFile2, OutFile);

   Stream_IO.Close(InFile1.File);
   Stream_IO.Close(InFile2.File);
   Stream_IO.Close(OutFile.File);



end Mkv2ps3;



